home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Programming / Amos / AMOSList-1297 / AMOSLIST / text0014.txt < prev    next >
Encoding:
Text File  |  1998-06-24  |  2.8 KB  |  87 lines

  1. > I seem to be stuck on a problem of detecting bob collisions.  My 
  2. > problems is that I need to test for so many.  I have a total of 12 
  3. > (or slightly more)  objects all of which must look out for eachother. 
  4. > Putting the collision detection routine in a loop is far too slow.  
  5. > Basically I have to call the collision detection procedure 100+ times 
  6. > per frame.  Is there an ultra fast way to do this?  My game is down 
  7. > to about 2 fps.  :(   Is there any way to do it without getting a 
  8. > special extension? 
  9.  
  10.    What sort of design are you using?
  11.    I normally rely on an optimized program-design to achieve the speed
  12.    in my projects, so...
  13.  
  14.    First, you need to set up your procedure _FINDHITNUM as well as
  15.    declare the global for it...
  16.  
  17.    Procedure _FINDHITNUM[FIRST, LAST]
  18.       HITFLAG=False : Rem  ...reset collision-flag
  19.       Rem  Run through the Col-list to see which Bob was Hit
  20.          For CHECKIT=FIRST To LAST
  21.             If Col(CHECKIT)
  22.                HITFLAG=CHECKIT : Rem  ...set flag to ID of object hit
  23.                CHECKIT=LAST : Rem ...my way to exit a loop
  24.             End If
  25.          Next CHECKIT
  26.    End Proc
  27.   
  28.    Global HITFLAG
  29.  
  30.    You have 12 objects which need to collide with any of the other 11,
  31.    so using Bob Col() you can "quickly" see if an object is colliding
  32.    with any of the others...
  33.  
  34.    This can be processed as follows:
  35.  
  36. For OBJECTNUM=0 to 11
  37.    Rem  Is this the first object?
  38.    If OBJECTNUM=0
  39.       Rem  yes, so need to check only against all "higher" objects...
  40.       If Bob Col(0, 1 To 11 )
  41.          _FINDHITNUM[1, 11]
  42.       End If
  43.  
  44.    Else
  45.       Rem  Is this the last object?
  46.       If OBJECTNUM=11
  47.          Rem  yes, so need to check only "lower" objects...
  48.          If Bob Col(11, 0 to 10)
  49.             _FINDHITNUM[0, 10]
  50.          End If
  51.       
  52.       Else
  53.          Rem  ObjectToCheck is between lowest and highest, so we 
  54.          Rem  need to perform two checks...
  55.          Rem  One for the objects lower than OBJECTNUM...
  56.          If Bob Col(OBJECTNUM, 0 To OBJECTNUM-1)
  57.             _FINDHITNUM[0, OBJECTNUM-1]   
  58.          Else
  59.             Rem and a second for objects higher than OBJECTNUM...
  60.             If Bob Col(OBJECTNUM, OBJECTNUM+1, 11)
  61.                _FINDHITNUM[OBJECTNUM+1, 11]
  62.             End If
  63.          End If
  64.        End If
  65.    End If
  66.   
  67.    Rem  This object has been checked, so we analyze the result...
  68.    If HITFLAG
  69.       Rem  If here, OBJECTNUM and HITFLAG objects have collided
  70.       Rem  so, do your processing...   
  71.    End If
  72. Next OBJECTNUM
  73.     
  74. This is a reasonably optimized design and AMOS should be able to
  75. sort out the collisions reasonably fast... :)
  76.  
  77. Let me know how you make out!!
  78.  
  79.  
  80.       Take  care,   
  81.       GARFIELD
  82.       _________________________
  83.       Current projects...
  84.       SideShooter(AMOS): 85% Complete
  85.       Website(http://www.sosbbs.com/~gbenjam): 20% Complete
  86.  
  87.